package com.jsh.erp.controller;

import com.jsh.erp.datasource.entities.CategoryValidation;
import com.jsh.erp.service.materialCategory.CategoryValidationService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/categoryValid")
public class CategoryValidationController {

    @Resource
    private CategoryValidationService categoryValidationService;

    /**
     * 新增 CategoryValidation
     */
    @PostMapping
    public int save(@RequestBody Map<String,Object> val) {
        return categoryValidationService.save(val);
    }

    /**
     * 更新 CategoryValidation
     */
    @PutMapping
    public int update(@RequestBody CategoryValidation categoryValidation) {
        return categoryValidationService.update(categoryValidation);
    }

    /**
     * 根据ID删除 CategoryValidation
     */
    @DeleteMapping("/{id}")
    public int delete(@PathVariable Long id) {
        return categoryValidationService.delete(id);
    }

    /**
     * 根据ID查询 CategoryValidation
     */
    @GetMapping("/{id}")
    public CategoryValidation findById(@PathVariable Long id) {
        return categoryValidationService.findById(id);
    }

    /**
     * 根据CategoryId查询对应的 CategoryValidation 列表
     */
    @GetMapping("/byCategory/{categoryId}")
    public List<CategoryValidation> findByCategoryId(@PathVariable Long categoryId) {
        return categoryValidationService.findByCategoryId(categoryId);
    }

    /**
     * 查询所有 CategoryValidation
     */
    @GetMapping
    public List<CategoryValidation> findAll() {
        return categoryValidationService.findAll();
    }
}
